<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ViewPage
 *
 * @author b4by
 */
class ViewPage extends MY_Controller {

	function __construct() {
		parent::__construct();
		$this->load->model('model_page');
	}

	public function index($id) {
		$page = $this->model_page->get_info($id);
//		pr($page);die;
		if (!$page)
			show_error(lang('page_not_found'));
		
		$this->load->model('model_page_catalogue');
		$cat_ids=$this->model_page_catalogue->get_list(array(
			'where' => array('page_id'	=> $page->id),
			'order'	=> array('cat_id','RANDOM')
		));
		$this->data['catalogue'] = $this->model_catalogue->get_info($cat_ids[0]->cat_id);
		
		$this->data['site_title'] = $page->title . ' | ' . $this->siteConfig->site_title;
		$this->data['page'] = $page;
		$this->data['temp'] = 'page/index';
		$this->data['others'] = $this->others($id);
		$this->load_view();
	}
	
	public function others($id)
	{
		$pages = $this->model_page->get_list(array(
			'where'=> array(
//				'cat_id'	=> $cat_id,
				'p.id <>'	=> $id,
				'time >' => now()-60*60*24*30
				),
			'limit'=> array(0,10),
			'order'=> array('id','RANDOM')
		));
		return $pages;
	}

}

?>
